<?php /** 获取权限列表 **/
require_once '../config/req.conf.php';
require_once '../utils/CommonMethods.php';
require_once '../utils/VerifyFormData.php';
require_once '../utils/DBUtils.php';

/* 1. 解析token获取用户信息 */
$headers = apache_request_headers(); // 请求头信息获取
$info = VerifyFormData::parseToken($headers['Authorization']);
if( CommonMethods::isEmpty($info) ) {
    RespJson::fail("token错误");
    return;
}

/* 2. 通过用户信息获取用户权限 */
DBUtils::init();
$sql = DBUtils::getSql("php_permission p,php_user_permission up")
    ->filter("p.id,p.name,p.component")
    ->where("up.`uId` = {$info['id']} AND p.`id` = up.`pId`")
    ->select();
$permissions = DBUtils::queryMulti($sql);
DBUtils::close();
$info['permissions'] = $permissions;

/* 3. 返回数据 */
RespJson::success(array(
    'userInfo' => $info
));
